<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="检测项"></u-navbar>
		<!-- <view class="list-item">
			<view class="list-bottom">
				<view>{{itemData.name}}</view>
			</view>
		</view> -->
		<u-form :model="itemData" ref="feedbackForm" label-width="100px" style="padding: 24rpx;">
			<u-form-item label-position="left" label="所属项目">
				{{itemData.projectName}}
			</u-form-item>
			<u-form-item label-position="left" label="标准要求">
				{{itemData.name}}
			</u-form-item>
			<u-form-item label-position="left" label="类别">
				{{itemData.standardType}}
			</u-form-item>
			<!-- 手动录入 -->
			<view v-if="itemData.numSet=='1'">
				<u-form-item label-position="left" label="总数" prop="total">
					<u-input type="text" :border="border" placeholder="请输入总数" v-model="itemData.total" />
				</u-form-item>
				<u-form-item label-position="left" label="不合格数量" prop="fail">
					<u-input type="text" :border="border" placeholder="请输入不合格数量" v-model="itemData.fail" />
				</u-form-item>
			</view>
			<!-- 单一数量 itemData.numSet=='2'"-->
			<view v-if="itemData.numSet=='2'">
				<u-form-item label-position="left" label="是否合格">
					<u-radio-group v-model="isGood" placement="row">
						<u-radio name=1 activeColor="green" @change="aa">合格</u-radio>
						<u-radio name=0 activeColor="red" @change="bb">不合格</u-radio>
					</u-radio-group>
				</u-form-item>
			</view>
			<!-- 绑定设备的检测项 v-if="bind!=null && bind"-->
			<view v-if="this.bind=='true'">
				<u-button @click="devClick()" type="success" style="margin: 24rpx;">检测设备情况</u-button>
				<u-form-item label-position="left" label="总数">
					{{itemData.total}}
				</u-form-item>
				<u-form-item label-position="left" label="不合格数量">
					{{itemData.fail}}
				</u-form-item>
			</view>
			<u-form-item label-position="left" label="简述检测情况" prop="situation">
				<u-input type="textarea" :auto-height="true" :border="border" placeholder="请输入检测情况" v-model="itemData.situation" />
			</u-form-item>
		</u-form>
		<view>
			<!-- <u-grid :col="3" :border="false">
				<u-grid-item>
					<!-- 图片上传 v-if="itemData.checkStyle.indexOf('2')>-1" 
					<u-button @click="submit(testItem.index--)" type="primary">上传图片</u-button>
				</u-grid-item>
				<u-grid-item>
					<!-- 视频上传 v-if="itemData.checkStyle.indexOf('3')>-1" 
					<u-button @click="submit(testItem.index--)" type="primary">上传视频</u-button>
				</u-grid-item>
				<u-grid-item>
					<!-- 隐患上报 
					<u-button @click="submit(testItem.index--)" type="primary">隐患上报</u-button>
				</u-grid-item>
			</u-grid> -->
			<u-grid :col="3" :border="false">
				<u-grid-item>
					<!-- 上一步 v-if="itemData.index != 0" -->
					<u-button v-if="itemData.index != 0" @click="submit(testItem.index--)" type="primary">上一步</u-button>
				</u-grid-item>
				<u-grid-item>
					<!-- 提交 v-if="itemData.index == this.totalNum-1" -->
					<u-button v-if="itemData.index == this.totalNum-1" @click="submit(testItem.index++)" type="primary">提交</u-button>
				</u-grid-item>
				<u-grid-item>
					<!-- 下一步 v-if="itemData.index != this.totalNum-1" -->
					<u-button v-if="itemData.index != this.totalNum-1" @click="submit(testItem.index++)" type="primary">下一步</u-button>
				</u-grid-item>
			</u-grid>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				border: true,
				testItem: {
					taskId: "",
					code: "",
					status: ""
				},
				totalNum: 0,
				itemData: {},
				isGood:0,
				bind:false,
				devType:'',
				rules: {
					total: [{
						required: true,
						message: '总数不能为空'
					}],
					fail: [{
						required: true,
						message: '不合格数量不能为空'
					}]
				}
			}
		},
		onShow() {
			this.initView(this.testItem)
		},
		onLoad(e) {
			this.testItem.taskId = e.taskId
			this.testItem.code = e.code
			this.testItem.status = e.status
			this.testItem.index = e.index
			this.totalNum = e.totalNum
			this.bind = e.bind
			this.devType = e.devType
		},
		methods: {
			// 跳转到设备详情列表
			devClick(){
				if(this.itemData.signal){
					uni.navigateTo({
						url:'/pages/testing/signalList?taskId='+ this.testItem.taskId + '&devType='+ this.devType
					})
				}else{
					uni.navigateTo({
						url:'/pages/testing/devList?taskId='+ this.testItem.taskId + '&devType='+ this.devType //+ '&checkStyle='+this.testItem.checkStyle
					})
				}
			},
			aa(n){console.log("aa",n)},
			bb(n){console.log("bb",n)},
			initView(val) {
				this.getInExamineStandard(val)
			},
			getInExamineStandard(val) {
				this.itemData = {}
				const _this = this;
				this.utils.request("/api/app/examine/getInExamineStandard", {taskId: val.taskId, code: val.code, index:val.index, status: val.status}, "post", "app", true).then(res => {
					this.itemData = res.data
					this.testItem.index = this.itemData.index
					this.loading=false
				}).catch(error => {
					this.loading=false
					console.log(error)
				})
			},
			prePage() {
				uni.navigateTo({
					url:'/pages/testing/testItem?taskId='+this.testItem.taskId + '&code=' + this.testItem.code + '&status=' + this.testItem.status + '&totalNum=' + this.totalNum + '&index=' + this.testItem.index
				})
			},
			submit() {
				const _this = this
				this.$refs.feedbackForm.validate(valid => {
					if (valid) {
						this.utils.request("/api/app/examine/saveInExamineStandard", this.itemData, "post", "app", true).then(res => {
							if(_this.itemData.index == _this.totalNum-1){
								uni.navigateTo({
									url: '/pages/testing/info?ucId=' + _this.itemData.taskId,
								});
							}else{
								_this.prePage()
							}
						}).catch(error => {
							console.log(error)
						})
					} else {
						console.log('验证失败');
					}
				});
			}
		},
		onReady() {
			this.$refs.feedbackForm.setRules(this.rules);
		},
	}
</script>

<style>
	.u-btn{
		width: 90%;
	}
	.u-grid{
		height: 48px;
		margin-bottom: 30rpx;
	}
</style>
